// Copyright (c) 2006, Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
//
// Author: arvin.chen
//
//

#ifndef ALGORITHM_SORT_SELECT_H_
#define ALGORITHM_SORT_SELECT_H_

#ifndef ALGORITHM_SORT_BASE_H_
#include "algorithm/sort/base.h"
#endif

namespace algorithm {
	namespace sort {
		
		template<typename T>
		class Select : public Base<T> {
		public:

			/**
			* Construction
			*
			* @param
			* @return
			*/
			Select() :
				Base<T>::Base(kSelect)
			{
				
			}

			/**
			* Destruction
			*
			* @param VOID
			* @return
			*/
			~Select()
			{

			}

			/**
			* sort
			*
			* @param T arr[]
			* @param int len
			* @return T
			*/
			virtual T* sort(T arr[], int len)
			{
				if (nullptr == arr || 1 >= len) return arr;
				for (int i = 0; i < len - 1; i++) {
					int min = i;
					for (int j = i + 1; j < len; j++) {
						if (arr[min] > arr[j]) min = j;
					}
					//swap
					std::swap(arr[i], arr[min]);
// 					T temp = arr[i];
// 					arr[i] = arr[min];
// 					arr[min] = temp;
				}
				return arr;
			}

		protected:
			/**
			* Assignment
			*
			* @param const Select& cbase
			* @return Select&
			*/
			Select& operator=(const Select& cbase);

			/**
			* Copy Construction
			*
			* @param const Select& cbase
			* @return
			*/
			Select(const Select& cbase);

		private:

		public:
		protected:
		private:

		};
	} // namespace algorithm 
} // namespace sort


#endif  // ALGORITHM_SORT_SELECT_H_
